package com.javasee.common.dbsharding;

import com.javasee.common.module.ModuleEnable;
import com.javasee.common.module.ModuleEnableConst;
import lombok.Data;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.HashMap;
import java.util.Map;

import static java.util.concurrent.TimeUnit.MINUTES;

@ModuleEnable(ModuleEnableConst.DBSHARDING)
@Data
@ConfigurationProperties(prefix="dbsharding")
public class DbShardingProperties {

    private volatile Integer minIdle = 5;

    private volatile Integer maxIdle = 15;

    private volatile Long maxLifetime = MINUTES.toMillis(3);

    private volatile Long idleTimeout = MINUTES.toMillis(1);

    private volatile Map<String, DataSourceProperties> datasources = new HashMap<>();

//    private volatile String driverClassName;

    private volatile Map<String, DbShardingTableInfo> tables = new HashMap<>();

    //2025年9月5日20:36:43
    //public final static String mapperScanBasePackages = "com.javasee.data.mapper";
    //public final static String[] mapperScanBasePackages = {"com..mapper","net..mapper","org..mapper"};
    //*用于匹配单个层级的包。
    //**用于匹配任意层级的包，包括所有子包和更深层次的子包。
    //public final static String[] mapperScanBasePackages = {"com.**.mapper","net.**.mapper","org.**.mapper"};
//    public  final static String mapperScanBasePackages = "com.**.mapper,net.**.mapper,org.**.mapper";
//    public final static String[] mapperScanBasePackages = {"com.**.mapper","net.**.mapper","org.**.mapper"};

    public  final static String mapperScanBasePackages = "com.**.mapper";
//    public  final static String mapperScanBasePackages = "com.javasee.rain.stock.mapper";
    private volatile String mapperXmlClassPath = "classpath*:mapper/*.xml";
    private volatile String typeHandlersPackage = "com.javasee.common.dbsharding.mybatis.typeHandler";

//    @Autowired ConditionContext context;

//    public DbShardingProperties(){
//        String value = ModuleEableCondition.context.getEnvironment().getProperty("dbsharding.mapper-scan-base-packages");
//        datasources = ModuleEableCondition.context.getEnvironment().getProperty("dbsharding.datasources", Map.class);
//        tables = ModuleEableCondition.context.getEnvironment().getProperty("dbsharding.tables", Map.class);
//
////        String value = SpringContextUtils.getApplicationContext().getEnvironment().getProperty("dbsharding.mapper-scan-base-packages");
//        this.setMapperScanBasePackages(value);
//    }

}
